/**
 * 
 */
package com.java.test.messagecenter.dto;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

import org.springframework.jdbc.core.RowMapper;

import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * @author 公告
 *
 */
public class NoticeInfo implements RowMapper<NoticeInfo> {

	// id
	private int id;

	// 标题
	private String title;

	// 内容
	private String content;

	// 发布时间
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private LocalDateTime pushTime;

	// 公告类型 1：普通公告 2：跑马灯
	private int noticeType;

	// 1:所有人，2：登陆 ；3：未登录
	private int powerType;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public LocalDateTime getPushTime() {
		return pushTime;
	}

	public void setPushTime(LocalDateTime pushTime) {
		this.pushTime = pushTime;
	}

	public int getNoticeType() {
		return noticeType;
	}

	public void setNoticeType(int noticeType) {
		this.noticeType = noticeType;
	}
	
	

	public int getPowerType() {
		return powerType;
	}

	public void setPowerType(int powerType) {
		this.powerType = powerType;
	}

	@Override
	public NoticeInfo mapRow(ResultSet rs, int rowNum) throws SQLException {

		NoticeInfo info = new NoticeInfo();

		info.setId(rs.getInt("id"));

		info.setContent(rs.getString("content"));

		info.setPushTime(rs.getTimestamp("push_time") == null ? null
				: rs.getTimestamp("push_time").toInstant().atZone(ZoneOffset.ofHours(8)).toLocalDateTime());

		info.setTitle(rs.getString("title"));

		info.setNoticeType(rs.getInt("notice_type"));
		
		info.setPowerType(rs.getInt("power_type"));

		return info;
	}

}
